<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport"
			content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../../css/common.css" media="all">
		<style>
			.layui-tab-brief>.layui-tab-more li.layui-this:after, .layui-tab-brief>.layui-tab-title .layui-this:after{
				border-bottom: 2px solid #009688
			}
		</style>
	</head>
	<body>
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15" id="ledgerDataView">
			</div>
			<script type="text/html" id="ledgerDataTPL">
				<div class="layui-col-md12">
					<div class="layui-card">
						<div class="layui-card-header">统计</div>
						<div class="layui-card-body">
							<div class="layui-carousel layadmin-carousel layadmin-backlog">
								<div>
									<ul class="layui-row layui-col-space10 accoutid_on">
										{{# layui.each(d, function(index, item){ }}
											<li class="layui-col-xs6">
												<a href="javascript:;" class="layadmin-backlog-body">
													<h3>{{item.name}}</h3>
													<p><cite
														 class="today_trans_count">{{ item.usable_amount ? '￥' + item.usable_amount : '-' }}</cite>
													</p>
												</a>
											</li>
											{{# }); 
														}}
									</ul>
								</div>
							</div>
						</div>
					</div>
				</div>
			</script>


			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">
						<!-- <div class="layui-card-header">客户管理</div> -->
						<div class="layui-card-body">
							<!-- 搜索 -->
							<form class="layui-form search" id="form" onsubmit="return false" action="##">
<!-- 								<div class="layui-inline search_inline">
									<label class="layui-form-label">账户编号：</label>
									<div class="layui-input-inline">
										<select name="accountid" class="record_type"></select>
									</div>
								</div> -->
								<div class="layui-inline search_inline">
									<label class="layui-form-label">会员编号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" placeholder="会员编号" name="customerid"
											autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">会员手机号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" placeholder="会员手机号"
											name="customerMobile" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline" id="timeall">
									<label class="layui-form-label">时间：</label>
									<div class="layui-input-inline" id="timeMin">
										<input class="layui-input" style="width: 300px;" id="choosetime"
											placeholder="时间" autocomplete="off">
										<input class="layui-input" type="text" name="stat_date" placeholder=""
											autocomplete="off" style="display: none;">
										<input class="layui-input" type="text" name="end_date" placeholder=""
											autocomplete="off" style="display: none;">
									</div>
									<div class="layui-input-inline" id="timeSelect" ></div>
								</div>
								<button class="layui-btn search_inline" lay-submit="" lay-filter="search"
									data-type="reload">搜索</button>
								<button class="layui-btn layui-btn-primary search_inline" type="reset">重置</button>
							</form>
							<div class="layui-tab layui-tab-brief" lay-filter="changetab">
								<ul class="layui-tab-title" id="view_ul" style="margin-bottom: 10px;"></ul>
							</div>
							<!-- 搜索 -->

							<table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate"></table>
							<script type="text/html" id="zizeng">
							{{d.LAY_TABLE_INDEX+1}}
							</script>
							<script type="text/html" id="test-table-operate-barDemo">
								<!-- <a class="layui-btn layui-btn-xs" lay-event="detail">详情</a> -->
							<a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
							<!-- <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
							  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> -->
							</script>
							
							<div id="line_details" >
								<div id="chart-money" style="height:400px;"></div>
								<table class="layui-hide" id="test-table-operate2" lay-filter="test-table-operate2"></table>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script type="text/html" id="time_ul">
			<select name="year" lay-verify="required">
				{{# layui.each(d, function(index, item){ }}
					<option value="{{ item}}">{{ item }}</option>
					{{# }); }}
			</select>
		</script>
		<script type="text/html" id="demo_ul">
			<li class="layui-this" lay-id='1'>明细</li>
		<!-- 	<li  lay-id='2'>按日</li>
			<li class="" lay-id='3'>按月</li>
			<li class="" lay-id='4'>按年</li> -->
			<!-- {{# layui.each(d, function(index, item){ }}
				<li class="" lay-id='{{ item.value }}'>{{ item.name }}</li>
				{{# }); }} -->
		</script>
		

		<script src="../../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../../js/common.js"></script>
		<script src="../../../../js/echarts.js"></script>
		<script>
			layui.config({
				base: '../../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'table', 'form', 'laytpl'], function() {
				var table = layui.table,
					$ = layui.$,
					form = layui.form,
					laytpl = layui.laytpl,
					laydate = layui.laydate,
					element = layui.element,
					admin = layui.admin;
					
					var getTpl = demo_ul.innerHTML,
						view = document.getElementById('view_ul');
						view.innerHTML = getTpl;
					laydate.render({
						elem: '#choosetime',
						type: 'datetime',
						range: true,
						done: function(value, date) {
							$('input[name=stat_date]').val(value.split(' - ')[0]);
							$('input[name=end_date]').val(value.split(' - ')[1]);
						}
					});
				var _data = {
					accountid: getParam('id'),
				}
				var name=getParam('name')
				console.log(name,'name222')
				if(getParam('type')){
					_data.type=getParam('type')
				}
				$('#timeSelect').css('display','none')
				var year=''
				var yearange=[]
				let num = new Date(); // 获取当前年
				year = num.getFullYear()
				$('select[name=year]').val(year)
				for (var i = 4; i > -1; i--) {
					let time = num.getFullYear() - i
					yearange.push(time)
				}
				view = document.getElementById('timeSelect');
				laytpl(time_ul.innerHTML).render(yearange, function(html) {
					view.innerHTML = html;
				});
				console.log(yearange,'yearange222')

				record_type_show('option');
				initdata();

				function accountid_on(e) {
					console.log(e);
				}


				
				function account(e) {
					$.get(server.sys_member_account_total_info, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								res.member_account.data.map((item, index) => {
									item.name = (e.find((val) => item.accountid == val.accountid))
										.accountname
								})

								console.log(res.member_account.data);
								var data = res.member_account.data;
								var ledgerDataView = document.getElementById('ledgerDataView');
								laytpl(ledgerDataTPL.innerHTML).render(data, function(html) {
									ledgerDataView.innerHTML = html;
								});
								$(".accoutid_on li").on('click', function() {
									console.log($(this).index());
									_data.accountid = data[$(this).index()].accountid
									$('select[name=accountid]').val(_data.accountid).toString()
									console.log($('select[name=accountid]').val());
									initdata()
									// $(this).addClass("active").siblings().removeClass("active");
								})
								// laytpl(ledgerDataTPL.innerHTML).render(data, function(html) {
								// 	ledgerDataView.innerHTML = html;
								// });
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}

				function initdata() {
					console.log(_data);
					$.get(server.sys_account_account,_data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								var aaa_list = res.account.data
								// account(aaa_list)
								table.render({
									elem: '#test-table-operate',
									url: server.op_querybillslist,
									height: 'full-105',
									toolbar: true,
									totalRow: true,
									cols: [
										[{
											width: 50,
											field: 'zizeng',
											title: '#',
											fixed: 'left',
											templet: '#zizeng'
										}, 
										{
											field: 'dates',
											width: 200,
											title: '日期',
										},
										{
											field: 'orderid',
											width: 200,
											title: '订单号',
										},{
											field: 'memberid',
											width: 100,
											title: '会员编号',
										},
										{
											field: 'name',
											width: 200,
											title: '会员姓名',
										},
										// {
										// 	field: 'accountid',
										// 	width: 150,
										// 	title: '账户编号'
										// }, 
										{
											field: 'accountname',
											width: 150,
											title: '账户',
											templet: function(d) {
												var aaa = aaa_list.find((val) => d
													.accountid == val.accountid)
												return '<span class="text_red_color">' + aaa
													.accountname + '</span>'
											},
										},
										{
											field: 'mobile',
											width: 150,
											title: '手机号',
										}, {
											field: 'fee',
											width: 100,
											title: '金额',
											totalRow: '{{= d.TOTAL_NUMS.toFixed(4) }}',
												templet: function(d) {												return d.income==0?'<span class="text_blue_color">-'+(d.fee).toFixed(4)+'</span>':'<span class="text_red_color">+'+(d.fee).toFixed(4)+'</span>'											}
										}, 
										{
											field: 'type',
											width: 200,
											title: '交易类型',
										}, 
										{
											field: 'notes',
											width: 300,
											title: '备注说明',
										},
										]
									],
									page: true,
									where: _data,
									limit: limit,
									limits: limits,
									request: {
										pageName: 'page',
										limitName: 'size',
									},
									parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
										return {
											"code": res.code, //解析接口状态
											"msg": res.msg, //解析提示文本
											"count": res.bills.pager.total, //解析数据长度
											"data": res.bills.data //解析数据列表
										};
									}
								});
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}
				//监听TAB
				element.on('tab(changetab)', function(elem) {
					status = this.getAttribute('lay-id');
					console.log(status,'elem0000')
					if (status == '2') {
						// 日
						tname = '%Y-%m-%d'
					} else if (status == '3') {
						// 月
						tname = '%Y-%m'
					} else if (status == '4') {
						// 年
						tname = '%Y'
					}
					if(status=='1' || status=='2'){
						$('#timeall').css('display','inline-block')
						$('#timeMin').css('display','inline-block')
						$('#timeSelect').css('display','none')
					}else if(status=='3'){
						$('#timeall').css('display','inline-block')
						$('#timeMin').css('display','none')
						$('#timeSelect').css('display','inline-block')
						year = num.getFullYear()
						$('select[name=year]').val(year)
						form.render()
						console.log(year,'year00000')
					}else{
						$('#timeall').css('display','none')
					}
					if(status==1){
						$('.layui-table-view').css('display','block')
						$('#line_details').css('display','none')
					}else{
						params.tname=tname
						if(status=='2'){
							params.starttime=$('input[name=stat_date]').val()
							params.endtime=$('input[name=end_date]').val()
						}else if(status=='3'){
							params.starttime=$('select[name=year]').val()+'-01-01 00:00:00'
							params.endtime=$('select[name=year]').val()+'-12-31 23:59:59'
						}
						getUrl()
						
						
						
						$('.layui-table-view').css('display','none')
						setTimeout(()=>{
							$('#line_details').css('display','block')
						},100)
					}
				});
				var params={
					
				}
				// 日统计 表格
				function initdataTable() {
					console.log(params,'paramsparams')
					$.get(server.sys_account_account,_data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								var aaa_list = res.account.data
								// account(aaa_list)
								table.render({
									elem: '#test-table-operate2',
									url: server.queryindex_sfzetotal,
									height: 'full-105',
									toolbar: true,
									totalRow: true,
									cols: [
										[{
											field: 'tname',
											width: '50%',
											title: '日期',
										},{
											field: 'sf_money100',
											width: '50%',
											title: '释放金额',
										}]
									],
									page: false,
									where: params,
									limit: limit,
									limits: limits,
									request: {
										pageName: 'page',
										limitName: 'size',
									},
									parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
									    initChartMoney(res.bills.data)  // 图表数据
										return {
											"code": res.code, //解析接口状态
											"msg": res.msg, //解析提示文本
											"count": res.bills.pager.total, //解析数据长度
											"data": res.bills.data ,//解析数据列表
											
											
										};
									}
								});
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}
			    function initdataATable(){
					console.log(params,'paramsparams')
					$.get(server.sys_account_account,_data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								var aaa_list = res.account.data
								// account(aaa_list)
								table.render({
									elem: '#test-table-operate2',
									url: server.queryindex_actotal,
									height: 'full-105',
									toolbar: true,
									totalRow: true,
									cols: [
										[{
											field: 'tname',
											width: '50%',
											title: '日期',
										},{
											field: 'ac_fee',
											width: '50%',
											title: 'A仓金额',
										}]
									],
									page: false,
									where: params,
									limit: limit,
									limits: limits,
									request: {
										pageName: 'page',
										limitName: 'size',
									},
									parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
									    initChartMoney(res.bills.data)  // 图表数据
										return {
											"code": res.code, //解析接口状态
											"msg": res.msg, //解析提示文本
											"count": res.bills.pager.total, //解析数据长度
											"data": res.bills.data ,//解析数据列表
											
											
										};
									}
								});
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}
				function initdataBTable(){
					console.log(params,'paramsparams')
					$.get(server.sys_account_account,_data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								var aaa_list = res.account.data
								// account(aaa_list)
								table.render({
									elem: '#test-table-operate2',
									url: server.queryindex_bctotal,
									height: 'full-105',
									toolbar: true,
									totalRow: true,
									cols: [
										[{
											field: 'tname',
											width: '50%',
											title: '日期',
										},{
											field: 'bc_fee',
											width: '50%',
											title: 'B仓金额',
										}]
									],
									page: false,
									where: params,
									limit: limit,
									limits: limits,
									request: {
										pageName: 'page',
										limitName: 'size',
									},
									parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
									    initChartMoney(res.bills.data)  // 图表数据
										return {
											"code": res.code, //解析接口状态
											"msg": res.msg, //解析提示文本
											"count": res.bills.pager.total, //解析数据长度
											"data": res.bills.data ,//解析数据列表
											
											
										};
									}
								});
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}
				function initdataCTable(){
					$.get(server.sys_account_account,_data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								var aaa_list = res.account.data
								// account(aaa_list)
								table.render({
									elem: '#test-table-operate2',
									url: server.queryindex_cctotal,
									height: 'full-105',
									toolbar: true,
									totalRow: true,
									cols: [
										[{
											field: 'tname',
											width: '50%',
											title: '日期',
										},{
											field: 'cc_fee',
											width: '50%',
											title: 'C仓金额',
										}]
									],
									page: false,
									where: params,
									limit: limit,
									limits: limits,
									request: {
										pageName: 'page',
										limitName: 'size',
									},
									parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
									    initChartMoney(res.bills.data)  // 图表数据
										return {
											"code": res.code, //解析接口状态
											"msg": res.msg, //解析提示文本
											"count": res.bills.pager.total, //解析数据长度
											"data": res.bills.data ,//解析数据列表
											
											
										};
									}
								});
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}
				function balanceTable(){
					if(_data.accountid){
						params.accountid=_data.accountid
					}
					console.log(params,'paramsparams')
					$.get(server.sys_account_account,_data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								var aaa_list = res.account.data
								// account(aaa_list)
								table.render({
									elem: '#test-table-operate2',
									url: server.queryindex_zyetotal,
									height: 'full-105',
									toolbar: true,
									totalRow: true,
									cols: [
										[{
											field: 'tname',
											width: '25%',
											title: '日期',
										},{
											field: 'ye_fee',
											width: '25%',
											title: '总余额',
										},{
											field: 'ye_fee100',
											width: '25%',
											title: '会员余额',
										},{
											field: 'ye_fee107',
											width: '25%',
											title: '商家余额',
										}]
									],
									page: false,
									where: params,
									limit: limit,
									limits: limits,
									request: {
										pageName: 'page',
										limitName: 'size',
									},
									parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
									    initChartMoney(res.bills.data)  // 图表数据
										return {
											"code": res.code, //解析接口状态
											"msg": res.msg, //解析提示文本
											"count": res.bills.pager.total, //解析数据长度
											"data": res.bills.data ,//解析数据列表
											
											
										};
									}
								});
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}
				function initChartMoney(vals) {
					console.log(vals,'record')
				    var chartMoney = echarts.init(document.getElementById('chart-money'));
				    // 指定图表的配置项和数据
				    var xAxisData = []
				    var yAxisData = []
				    xAxisData = (vals.map(v => v.tname)).reverse();
					if (name == 'A仓已释放') {
						yAxisData = vals.map(v => v.sf_money100).reverse();
					} else if (name == '商家金额' || name == '会员余额') {
						yAxisData = vals.map(v => v.ye_fee).reverse();
					} else if (name == 'A仓金额') {
						yAxisData = vals.map(v => v.ac_fee).reverse();
					} else if (name == 'B仓金额') {
						yAxisData = vals.map(v => v.bc_fee).reverse();
					} else if (name == 'C仓金额') {
						yAxisData = vals.map(v => v.cc_fee).reverse();
					}
					if(vals.length==0){
						xAxisData=['0']
						yAxisData=['0']
					}
				  
					var chartMoneyOption = {
						tooltip: {
							trigger: 'axis',
							axisPointer: {
								type: 'cross',
								label: {
								  backgroundColor: '#6a7985'
								}
							}
						},
						xAxis: {
							type: 'category',
							data: xAxisData
						},
						yAxis: {
							type: 'value',
							data: ''
						},
						legend: {
							data: [
								name == 'A仓已释放'?'释放总额':(name == '商家金额'||name == '会员余额')?'总余额':name == 'A仓金额'?'A仓金额':name == 'B仓金额'?'B仓金额':name == 'C仓金额'?'C仓金额':'']
						},
						series: [
							{
								name: name == 'A仓已释放'?'释放总额':(name == '商家金额'||name == '会员余额')?'总余额':name == 'A仓金额'?'A仓金额':name == 'B仓金额'?'B仓金额':name == 'C仓金额'?'C仓金额':'',
								data: yAxisData,
								type: 'bar',
								areaStyle: {},
								itemStyle : { normal: {label : {show: true}}}
							}
						],
						grid: [
							{
								left: '5%',
								right: '5',
								top: 40
							}
						]
					};
				    chartMoney.setOption(chartMoneyOption);
				}


				//监听搜索
				form.verify({
					memberid: function(value, item) { //value：表单的值、item：表单的DOM对象
						if (!value) {
							return '姓名不能为空';
						}
					}
				});

				//监听搜索
				form.on('submit(search)', function(data) {
					_data = data.field
					if(status=='1'){  // 明细
						initdata();
					}else{
						if(status=='2'){
							params.starttime=$('input[name=stat_date]').val()
							params.endtime=$('input[name=end_date]').val()
						}else if(status=='3'){
							params.starttime=$('select[name=year]').val()+'-01-01 00:00:00'
							params.endtime=$('select[name=year]').val()+'-12-31 23:59:59'
						}
						getUrl()
					}
					return false;
				});

				$("button[type=reset]").on("click", function() {
					$('input[name=stat_date]').val('')
					$('input[name=end_date]').val('')
					_data = {}
					if(status=='1'){
						initdata();
					}else{
						getUrl()
					}
					document.getElementById("form").reset();
				});
				
				function getUrl(){
					if(name=='A仓已释放'){
						initdataTable()
					}else if(name=='商家金额'||name=='会员余额'){
						balanceTable()
					}else if(name=='A仓金额'){
						initdataATable()
					}else if(name=='B仓金额'){
						initdataBTable()
					}else if(name=='C仓金额'){
						initdataCTable()
					}
				}

				//监听表格复选框选择
				table.on('checkbox(test-table-operate)', function(obj) {
					console.log(obj)
				});
				


				//监听工具条
				table.on('tool(test-table-operate)', function(obj) {
					var data = obj.data;
					if (obj.event === 'detail') {
						layer.open({
							type: 2,
							title: '详情',
							shadeClose: false,
							shade: 0.5,
							area: ['600px', '75%'],
							content: 'model/customer_detail.html?id=' + data.memberid,
							end: function() {
								// initdata();
							}
						});
					} else if (obj.event === 'del') {
						layer.confirm('真的删除行么', function(index) {
							obj.del();
							layer.close(index);
						});
					} else if (obj.event === 'edit') {
						layer.open({
							type: 2,
							title: '修改',
							shadeClose: true,
							shade: false,
							maxmin: true, //开启最大化最小化按钮
							area: ['893px', '600px'],
							content: 'model/customer_edit.html?id=' + data.id,
							end: function() {

							}
						});
					} else if (obj.event === 'upreport') {
						layer.open({
							type: 2,
							title: '上传报告',
							shadeClose: false,
							shade: 0.5,
							area: ['500px', '300px'],
							content: 'model/up_report.html?id=' + data.id,
							end: function() {}
						});
					}
				});

				var $ = layui.$,
					active = {
						getCheckData: function() { //获取选中数据
							var checkStatus = table.checkStatus('test-table-operate'),
								data = checkStatus.data;
							layer.alert(JSON.stringify(data));
						},
						getCheckLength: function() { //获取选中数目
							var checkStatus = table.checkStatus('test-table-operate'),
								data = checkStatus.data;
							layer.msg('选中了：' + data.length + ' 个');
						},
						isAll: function() { //验证是否全选
							var checkStatus = table.checkStatus('test-table-operate');
							layer.msg(checkStatus.isAll ? '全选' : '未全选')
						}
					};

				$('.test-table-operate-btn .layui-btn').on('click', function() {
					var type = $(this).data('type');
					active[type] ? active[type].call(this) : '';
				});

			});
		</script>
	</body>
</html>